{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "'ls' 不是内部或外部命令，也不是可运行的程序\n",
      "或批处理文件。\n"
     ]
    }
   ],
   "source": [
    "import scipy.sparse as sp\n",
    "import numpy as np\n",
    "\n",
    "A = sp.rand(4, 3, 0.4, format='coo')\n",
    "\n",
    "A.todense()\n",
    "\n",
    "np.savez('A_coo.npz', V=A.data, I=A.row, J=A.col, dims=A.shape)\n",
    "\n",
    "!ls -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[0.        , 0.        , 0.74356036],\n",
       "        [0.        , 0.86471665, 0.86336337],\n",
       "        [0.        , 0.        , 0.        ],\n",
       "        [0.92051913, 0.        , 0.        ]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = None\n",
    "fh = np.load('A_coo.npz')\n",
    "V = fh['V']\n",
    "I = fh['I']\n",
    "J = fh['J']\n",
    "dm = fh['dims']\n",
    "fh.close()\n",
    "A = sp.coo_matrix((V, (I, J)), shape=dm)\n",
    "A.todense()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
